package demo2;

import demo2.SingletonHungry;

/**
 * 测试饿汉模式在多线程的环境下
 */
public class TestHungryMul {
    public static void main(String[] args) {
        Thread[] threads=new Thread[10];
        for (int i = 0; i < threads.length; i++) {
            threads[i]=new Thread(()->{
                SingletonHungry instance=SingletonHungry.getInstance();
                System.out.println(instance);
            });
        }
        for (Thread t:threads
             ) {
            t.start();
        }
        //饿汉模式下也，没有问题
    }
}
